 /*
  * Copyright (c) 2021, 2023, yishun.cn All rights reserved.
  *
  */
 package cn;

 import java.io.FileInputStream;
 import java.util.Date;
 import java.time.LocalDate;
 import java.time.LocalTime;
 import java.time.LocalDateTime;
 import cn.shun.config.SpringConfig;
 import cn.shun.entity.Goods;
 import cn.shun.mapper.GoodsMapper;
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

 /**
  * <p>Project: MyBatis2023 - GoodsDemo
  * <p>Powered by yishun On 2023-01-30 20:19:07
  *
  * @author yishun [2465734101@qq.com]
  * @version 1.0
  * @since 17
  */
 @SpringJUnitConfig(SpringConfig.class)
 public class GoodsDemo {
     @Autowired
     GoodsMapper gm;

     @Test
     @DisplayName("商品插入")
     void goodsInsert() {
         Goods goods = new Goods();
         goods.setId(0L);
         goods.setName("键盘");
         goods.setPrice(98.2);
         goods.setLocalTime(LocalTime.now());
         goods.setLocalDate(LocalDate.now());
         goods.setCreateTime(LocalDateTime.now());
         goods.setUpdateTime(new Date());
         goods.setOnline(false);
         try (FileInputStream fis = new FileInputStream("mouse.jpg")) {
             goods.setGoodsPic(fis.readAllBytes());
         } catch (Exception e) {
             e.printStackTrace();
         }
         goods.setGoodsDescription("这是一个游戏鼠标");
         int i = gm.save(goods);
         if (i > 0) {
             System.out.println("商品添加成功");
         }
     }

 }
